package com.reform.controller.phase;


import com.reform.res.Result;
import com.reform.service.IPhaseFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLException;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author mortale
 * @since 2021-09-21
 */
@Api(tags = "PhaseFileController")
@RestController
@RequestMapping("/phase-file")
public class PhaseFileController {

    @Autowired
    IPhaseFileService phaseFileService;

    @ApiOperation(value = "获取所有阶段检查文件信息")
    @GetMapping("/getAllPhaseFile")
    public Result getAllPhaseFile() throws SQLException {
        return phaseFileService.getAllPhaseFile();
    }

    @ApiOperation(value = "根据阶段检查编号获取阶段检查文件信息")
    @PostMapping("/getPhaseFileByPhaseId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phaseId", value = "阶段检查编号", paramType = "query", dataTypeClass = String.class, required = true),
    })
    public Result getPhaseFileByPhaseId(String phaseId) throws SQLException {
        return phaseFileService.getPhaseFileByPhaseId(phaseId);
    }

    @ApiOperation(value = "根据项目编号和阶段检查编号获取阶段检查文件信息")
    @PostMapping("/getPhaseFileById")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "proId", value = "项目编号", paramType = "query", dataTypeClass = String.class, required = true),
            @ApiImplicitParam(name = "phaseId", value = "阶段检查编号", paramType = "query", dataTypeClass = String.class, required = true),
    })
    public Result getPhaseFileById(String proId, String phaseId) throws SQLException {
        return phaseFileService.getPhaseFileById(proId, phaseId);
    }

    @ApiOperation(value = "根据项目编号获取阶段检查文件信息")
    @PostMapping("/getPhaseFileByProId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "proId", value = "项目编号", paramType = "query", dataTypeClass = String.class, required = true),
    })
    public Result getPhaseFileByProId(String proId) throws SQLException {
        return phaseFileService.getPhaseFileByProId(proId);
    }

    @ApiOperation(value = "添加阶段检查文件信息")
    @PostMapping("/addPhaseFiles")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phaseId", value = "阶段检查编号", paramType = "query", dataTypeClass = String.class, required = true),
            @ApiImplicitParam(name = "proId", value = "项目编号", paramType = "query", dataTypeClass = String.class, required = true),
            @ApiImplicitParam(name = "phaseFileInfo", value = "filename，filesize，pfPath，status。JSON字符串", paramType = "query", dataTypeClass = String.class, required = true),
    })
    public Result addPhaseFiles(String phaseId, String proId, String phaseFileInfo) {
        return phaseFileService.addPhaseFiles(phaseId, proId, phaseFileInfo);
    }

    @ApiOperation(value = "删除阶段检查文件信息")
    @PostMapping("/deletePhaseFile")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pfId", value = "阶段文件检查编号", paramType = "query", dataTypeClass = String.class, required = true),
    })
    public Result deletePhaseFile(String pfId) {
        return phaseFileService.deletePhaseFile(pfId);
    }

    @ApiOperation(value = "根据阶段文件检查编号修改阶段文件检查状态")
    @PostMapping("/updateStatusByPfId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pfId", value = "阶段文件检查编号", paramType = "query", dataTypeClass = String.class, required = true),
            @ApiImplicitParam(name = "status", value = "阶段文件检查状态", paramType = "query", dataTypeClass = Integer.class, required = true),
    })
    public Result updateStatusByPfId(String pfId, Integer status) throws SQLException {
        return phaseFileService.updateStatusByPfId(pfId, status);
    }

}
